<?php

use \Nette\Application\UI\Form,
	florbalMohelnice\Forms\OrderForm,
	 Nette\Diagnostics\Debugger;
/**
 * Desc. SecuredPresenter
 *
 * @author Michal Fučík michal.fuca.fucik@gmail.com
 * @package fbcmoh
 */
 abstract class SecuredPresenter extends BasePresenter {
	 
	const USER_PROFILE_REQUIRED = "req";
	const USER_PROMPT_REQUIRED = "Vyplň si svůj profil, prosím";
	
	const USER_PROFILE_EDITED = "eee";
	const USER_PROMPT_EDITED = "Váš profil čeká na schválení";
	
	/** @var array of users for select input */
	private $selectUsers;
	
	public function getSelectUsers() {
		if (!isset($this->selectUsers)) $this->selectUsers = $this->getUserModel()->getSelectUsers();
		return $this->selectUsers;
	}
	
	/** @var logged in user kid*/
	private $userId;
	
	public function getUserId() {
		return (integer) $this->userId;
	}
	
	public function startup() {
		
		parent::startup();
		
		$user = $this->getUser();
		$this->userId = $user->getId();
		if (!$user->isLoggedIn()){
			if ($user->getLogoutReason() === \Nette\Security\User::INACTIVITY) {
                $this->flashMessage('Uplynula doba neaktivity! Systém vás z bezpečnostních důvodů odhlásil.', 'warning');
				$this->redirect('Auth:logIn');
            } else {
				$backlink = $this->getApplication()->storeRequest();
				$this->redirect('Auth:logIn', array('backlink' => $backlink));
			}
			
			// authorization part
			/*
			if (!$user->isAllowed($this->name, $this->action)) {
                $this->flashMessage('Na vstup do této sekce nemáte dostatečné oprávnění!', 'warning');
                $this->redirect('Homepage:default');
            }*/
		}
			
	}
	
	public function beforeRender(){
		$p = $this->user->identity->data['profile_required'];
		// TODO DB || const
		switch ($p) {
			case self::USER_PROFILE_EDITED:
				$prompt = self::USER_PROMPT_EDITED;
				break;
			case self::USER_PROFILE_REQUIRED:
				$prompt = self::USER_PROMPT_REQUIRED;
				break;
			default : $prompt = "";
		}
		$this->template->webProfilePrompt = $prompt;
	}
	public function actionDefault() {}
	public function renderDefault() {}
	
	
}

